﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="../Script/easyui/jquery.min.js"></script>
    <script src="../Script/easyui/jquery.easyui.min.js"></script>
    <link href="../Script/easyui/themes/default/easyui.css" rel="stylesheet" />    
    <link href="../Script/easyui/themes/icon.css" rel="stylesheet" />
    <script src="../Script/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        var json = {
            "total": 3,
            "rows": [{
                "userid": "1",
                "user": "XC001",
                "user1": "41%草甘膦异丙胺盐水剂",
                "user2": "xc60332",
                "user3": "水剂",
                "user4": "除草",
                "user5": "12",
                "user6": "2013-12-2",
                "user7": "济南小区232路"
            },
                {
                    "userid": "2",
                    "user": "XC032",
                    "user1": "5%高效氯氟氰菊酯微乳剂",
                    "user2": "xc10345",
                    "user3": "微乳剂",
                    "user4": "杀虫",
                    "user5": "2",
                    "user6": "2014-5-2",
                    "user7": "济南小区232路",
                },
                {
                    "userid": "3",
                    "user": "XC1201",
                    "user1": "40%稻瘟灵乳油",
                    "user2": "xc3432",
                    "user3": "水剂",
                    "user4": "杀菌",
                    "user5": "19",
                    "user6": "2014-2-2",
                    "user7": "济南小区232路",
                }]
        };
        $(function () {
            InitGird();
            InitSearch();
        });
        //初始化表格
        function InitGird() {
            $('#tab_list').datagrid({
                title: '药品药械列表', //表格标题
                //url: 'content.json', //请求数据的页面
                sortName: 'user', //排序字段
                idField: 'user', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
                //height: $(parent.document).find("#mainPanle").height() - 35 > 0 ? $(parent.document).find("#mainPanle").height() - 35 : 500, //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                //frozenColumns: [[//冻结的列，不会随横向滚动轴移动

                //]],
                columns: [[
                    { field: 'ckb', checkbox: true },
	                { title: '编号', field: 'user', width: 150, sortable: true },
                    { title: '名称', field: 'user1', width: 150 },
                    { title: '型号', field: 'user2', width: 180 },
                    { title: '功能', field: 'user3', width: 120 },
                    { title: '参数', field: 'user4', width: 150 },
                    { title: '数量', field: 'user5', width: 150 },
                    { title: '最后入库时间', field: 'user6', width: 150 },                    
                    {
                        title: '操作', field: 'userid', width: 80, formatter: function (value, row, index) {
                            return '<a style="color:red" href="javascript:" onclick="EditData(' + value + ');$(this).parent().click();return false;">入库</a> <a style="color:red" href="javascript:" onclick="EditData(' + value + ');$(this).parent().click();return false;">出库</a>';
                        }
                    }
                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "query" },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true //行号
            });
            $('#tab_list').datagrid("loadData", json);

        }
        //初始化搜索框
        function InitSearch() {
            $("#ipt_search").searchbox({
                width: 200,
                //iconCls: 'icon-save',
                searcher: function (val, name) {
                    $('#tab_list').datagrid('options').queryParams.search_type = name;
                    $('#tab_list').datagrid('options').queryParams.search_value = val;
                    $('#tab_list').datagrid('reload');
                },
                prompt: '请输入查询信息'
            });
        }

        //添加        
        function OpenWin() {
            //parent.addTab("增加新教师", "/userInfo/add.aspx", "icon icon-add");//在其它窗口
            $("#edit").dialog("open");
            $("#edit-buttons a:first").attr("onclick", "Add(0); return false;")
        }
        function GetInputData(id, cmd) {
            var postdata = "{ \"action\":\"" + cmd + "\",";
            $("#" + id + " input[type!='checkbox']").each(function () {
                postdata += "\"" + $(this).attr("name") + "\":\"" + $(this).val() + "\",";
            });
            $("#" + id + " input[type='checkbox']").each(function () {
                postdata += "\"" + $(this).attr("name") + "\":\"" + this.checked + "\",";
            });
            postdata = postdata.substr(0, postdata.length - 1);
            postdata += "}";
            return eval("(" + postdata + ")");
        }
        function Add(uid) {
            if (!$("#form_edit").form("validate")) {
                return;
            }
            var json = GetInputData('edit', 'submit');
            json.id = uid;
            $.post(location.href, json, function (data) {
                $.messager.alert('提示', data, 'info', function () {
                    if (data.indexOf("成功") > 0) {
                        console.info(data);
                        $("#tab_list").datagrid("reload");
                        $("#edit").dialog("close");
                    }

                });
            });
        }

        //修改链接 事件
        function EditData(uid) {
            $("#edit").dialog("open");
            $("#btn_add").attr("onclick", "Add(" + uid + "); return false;")

            $.post(location.href, { "action": "queryone", "id": uid }, function (data) {
                var dataObj = eval("(" + data + ")"); //转换为json对象    
                console.info(dataObj);
                $("#form_edit").form('load', dataObj);
            });
        }
        //删除按钮事件
        function DelData(id) {
            $.messager.confirm('提示', '确认删除？', function (r) {
                if (r) {
                    var selected = "";
                    if (id <= 0) {
                        $($('#tab_list').datagrid('getSelections')).each(function () {
                            selected += this.JSON_userid + ",";
                        });
                        selected = selected.substr(0, selected.length - 1);
                        if (selected == "") {
                            $.messager.alert('提示', '请选择要删除的数据！', 'info');
                            return;
                        }
                    }
                    else {
                        selected = id;
                    }
                    $.post(location.href, { "action": "del", "cbx_select": selected }, function (data) {
                        $.messager.alert('提示', data, 'info', function () { $("#tab_list").datagrid("reload"); });
                    });

                }
            });
        }
    </script>
</head>
<body>
    <table id="tab_list">
        </table>
        <div id="tab_toolbar" style="padding: 4px;">
            <table cellpadding="0" cellspacing="0" style="width: 100%">
                <tr>

                    <td style="padding-left: 2px">


                        <a href="#" onclick="OpenWin();" id="a_add"
                            class="easyui-linkbutton" iconcls="icon-add">入库</a>

                        <a href="#" onclick="DelData(0);return false;" id="a_del" class="easyui-linkbutton" iconcls="icon-cancel">出库</a>

                    </td>
                    <td style="text-align: right; padding-right: 15px">
                        <input id="ipt_search" menu="#search_menu" />
                        <div id="search_menu" style="width: 120px">
                            <div name="usernum">
                                名 称
                            </div>
                            <div name="username">
                                姓 名
                            </div>
                        </div>
                    </td>
                </tr>
            </table>

        </div>
</body>
</html>
